cd "${supp_data}/county1980/"
do "${supp_data}/county1980/nhgis0016_ds104_1980_county.do"

egen pop_race = rowtotal(c9d*)

gen c80p_wh = c9d001/pop_race
gen c80p_bl = c9d002/pop_race
gen c80p_ai = (c9d003+c9d004+c9d005)/pop_race
gen c80p_api = (c9d006+c9d007+c9d008+c9d009+c9d010+c9d011+c9d012+c9d013+c9d014)/pop_race
gen c80p_othr = (c9d015)/pop_race

egen pop_hisp= rowtotal(c9e*)
gen c80p_hisp = 1-(c9e001/pop_hisp)

egen pop_age = rowtotal(c67*)
gen c80p_a5 = (c67001+c67002+c67003+c67004)/pop_age
gen c80p_a65 = (c67024+c67002+c67025+c67026)/pop_age

gen d1 = pop_race-pop_hisp
gen d2 = pop_race-pop_age
summ d1 d2
drop d1 d2

save  "${supp_data}/county1980/temp1" , replace
clear

do  "${supp_data}/county1980/nhgis0017_ds107_1980_county.do"
egen pop_educ = rowtotal(dhm*)

gen c80p_hsdrop = (dhm001+dhm002)/pop_educ
gen c80p_baplus = dhm005/pop_educ

rename dil001 c80med_faminc
rename div001 c80med_inc

egen pop_pov = rowtotal(djd*)
gen c80p_pov75 = djd001/pop_pov
gen c80p_pov200 = (djd001+djd002+djd003+djd004)/pop_pov
gen c80p_pov100 = di8002/(di8001+di8002)

save  "${supp_data}/county1980/temp2" , replace
clear

do  "${supp_data}/county1980/nhgis0016_ds110_1980_county.do"
egen pop_lf = rowtotal(dr*)
gen c80r_unemp= dr0003/(dr0002+dr0003)
gen c80r_lfp = (dr0002+dr0003)/(dr0002+dr0003+dr0004)
save  "${supp_data}/county1980/temp3" , replace
clear


do "${supp_data}/county1980/nhgis0016_ds111_1980_county.do"
rename dv7001 c80_pop

keep regiona divisiona state statea* smsaa county countya c80*
merge 1:1 statea countya using  "${supp_data}/county1980/temp1", gen(_m_race) keepusing(c80* pop_*)
merge 1:1 statea countya using  "${supp_data}/county1980/temp2", gen(_m_educ) keepusing(c80* pop_*)
merge 1:1 statea countya using  "${supp_data}/county1980/temp3", gen(_m_pov) keepusing(c80* pop_*)


rename statea state_fips_str
rename countya county_fips_str80
destring state_fips_str, gen(state_fips) 


gen county_fips_str = county_fips_str80
replace county_fips_str = "086" if county_fips_str80=="025" // Dade County, Florida (12-025): Renamed as Miami-Dade County (12-086) effective July 22, 1997.
destring county_fips_str, gen(county_fips) 

gen fips_str = state_fips+county_fips
destring fips_str, gen(fips) 
order regiona divisiona state* county* fips*
drop _m_* pop_*
format state county %10s
format regiona divisiona state_fips_str county_fips_str smsaa %5s

save  "${supp_data}/county_chars1980", replace

cd "${main}"
 